package com.wjk.cms.dao;

import com.wjk.cms.pojo.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author WUGN
 * @des
 * @date 2021/9/13 10:41
 */
@Repository
public interface OrderRepository extends JpaRepository<Order, Long>, JpaSpecificationExecutor<Order> {


    Order getByCode(String Code);

    @Query(nativeQuery = true, value = "select o.* from t_order o left join product p on o.item_code=p.code where" +
            " p.user_code=?1  and o.type=0 order by o.id desc limit ?2,?3")
    List<Order> productOrderList(String code, int pageNo, int pageSize);

    @Query(nativeQuery = true, value = "select o.* from t_order o left join customer c on o.item_code=c.code where" +
            " c.user_code=?1 and o.type=3 order by o.id desc limit ?2,?3")
    List<Order> customerOrderList(String code, int pageNo, int pageSize);

    Order getByCardId(Long cardId);
}
